package com.yy.job.common.enums;

import java.util.stream.Stream;

import org.apache.commons.lang3.StringUtils;

/**
 * 任务执行方式
 * 
 * @author eleven.li
 *
 */
public enum JobExecuteTypeEnum {

	STANDARD("S", "标准扫描执行", "创建之后，等待扫描器扫描之后进入执行队列"),
	LOCAL("L", "本地执行", "创建之后，立即锁定并进入本机的执行队列，需要等待扫描器定时唤起处理本地队列。在等待期间若本机重启，则会进入标准扫描执行流程"),
	PRIORITY("P", "优先级(立即)执行", "创建之后，立即锁定并进入本机的执行队列，并且立即执行。");

	private String code;
	private String name;
	private String description;

	JobExecuteTypeEnum(String code, String name, String description) {
		this.code = code;
		this.name = name;
		this.description = description;
	}

	public String getCode() {
		return this.code;
	}

	public String getName() {
		return this.name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public static JobExecuteTypeEnum findByCode(String code) {
		if (StringUtils.isEmpty(code)) {
			return null;
		}

		return Stream.of(JobExecuteTypeEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
	}

}
